home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 1.iso
/
ARGONET
/
PD
/
MATHS
/
RLAB
/
RLAB125.ZIP
/
!RLaB
/
examples
/
collatz
< prev
next >
Wrap
Text File
|
1995-05-20
|
460b
|
35 lines
//
// The 3n + 1 problem
//
collatz = function(start)
{
local(c, n);
c = n = start;
while(n > 1)
{
if(mod(n,2) == 0) {
n = n/2;
else
n = 3*n + 1;
}
c = [c, n];
}
return c;
};
//
// Try it out
//
c = collatz(100);
plgrid ();
pltitle ( "RLaB Collatz Example" );
xlabel ( "Indeplendent Variable" );
ylabel ( "Deplendent Variable" );
plot( [1:c.nc; c]' );
pause ();
plgrid ( ,"bcgnstlv");
plot( [1:c.nc; c]' );